package com.mendmix.tutorial.support.auth;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.mendmix.common.http.HttpRequestEntity;
import com.mendmix.gateway.api.AccountApi;
import com.mendmix.gateway.model.AccountScope;

@Service
public class DefaultAccountApi implements AccountApi {

	@Value("${service.baseUrl:http://tutorial-service}/user/validate")
	private String userValidateUrl;
	
	@Override
	public LoginUserInfo validateAccount(String type,String accountName, String password)  {
		LoginUserInfo authUser;

		Map<String, String> param = new HashMap<>(2);
		param.put("account", accountName);
		param.put("password", password);
		authUser = HttpRequestEntity.post(userValidateUrl).body(param).backendInternalCall().execute().toObject(LoginUserInfo.class);

		return authUser;
	}

	@Override
	public List<AccountScope> findAccountScopes(String accountId) {
		return null;
	}

}
